// import store from '@/store'
import axios from 'axios'
// import { getToken } from '@/utils/auth'

const service = axios.create({
  baseURL: '/api',
  timeout: 8000
})
const getToken = () => window.localStorage.getItem('token')
service.interceptors.request.use(
  config => {
    if (getToken()) {
      // config.headers.Authorization = getToken()
      // const token = window.localStorage.getItem('token')
      config.headers.Authorization = getToken()
    }
    return config
  }, error => {
    console.log(error)
    return Promise.reject(error)
  })

service.interceptors.response.use(
  response => {
    const res = response.data
    return res
  },
  error => {
    console.log(error)

    const { status } = error.response

    if (status === 401) {
      // to re-login
      // 提示没有权限，重新登录
    }

    // const message = error.message
    // Toast(message, { position: 'bottom' })

    return Promise.reject(error)
  })

export default service
